<?php

/**
 * 前台 案例显示 模块 Controller
 * ============================================================================
 * TBlog TBlog博客系统　BY Tmac PHP MVC framework
 * $Author: zwt007 $  <zwttmac@qq.com>
 * $Id: news.php 39 2011-07-11 17:12:35Z zwt007 $
 * http://www.t-mac.org；
 */
class anliAction extends Action
{

    private $tmp_model;
    private $show_model;
    private $article_model;
    private $index_model;
    private $difang_model;
    private $hotel_model;
    private $userinfo;

    public function _init()
    {
        $this->assign('action', $_GET['TMAC_ACTION']);
        $this->tmp_model = Tmac::model('news');
        $this->show_model = Tmac::model('show');
        $this->index_model = Tmac::model('index');
        $this->difang_model = Tmac::model('difang');
        $this->article_model = Tmac::model('article', 'admin');
        $this->hotel_model = Tmac::model('hotel');        

        $username = $this->H($this->getParam('username'));
        $this->userinfo = $this->difang_model->getUserinfo($username);
        
        $this->config = $this->index_model->getCommon($this->userinfo);

        $nav_array = $this->difang_model->getCategoryArray($this->userinfo['uid'], 0);

        $hotel_list_nopage_array = $this->show_model->getHotelListNoPage($this->userinfo['uid'], 5);
        //left hotel nopage
        $news_list_nopage_array = $this->show_model->getArticleNewsListNopage(8, $this->userinfo['uid']);
        //left 会议常识
        $hycs_cid = 70;
        $hycs_list_nopage_array = $this->show_model->getArticleNewsListNopageB($hycs_cid, $this->userinfo['uid']);

        $this->assign('hotel_list_nopage_array', $hotel_list_nopage_array);
        $this->assign('news_list_nopage_array', $news_list_nopage_array);
        $this->assign('hycs_list_nopage_array', $hycs_list_nopage_array);
        $this->assign('hycs_cid', $hycs_cid);
        $this->assign('nav_array', $nav_array);
        $this->assign('userinfo', $this->userinfo);
    }

    public function index()
    {
        $cid = intval($this->getParam('cid'));
        $cid = empty($cid) ? 7 : $cid;
        //取category信息
        $catinfo = $this->show_model->getCategoryInfoById($cid, $this->userinfo['uid']);
        //取文章信息
        $url = PHP_SELF . '?m=anli&username=' . $this->userinfo['username'] . '&cid=' . $cid . '&page=';
        global $cat_ids;
        $cat_ids = '';
        $cat_ids = $this->index_model->getSonTreeList($cid, $this->userinfo['uid']);
        $list = $this->tmp_model->getArticleList($url, $cat_ids, $this->userinfo['uid']);

        //下级栏目        
        $url = 'anli';
        $parent = 2;    //父级id                
        $this->index_model->getCategoryList(7, $url, $this->userinfo['uid'], $this->userinfo['username'], $this->config['cfg_indexurl']);

        $this->assign('cid', $cid);
        $this->assign('catinfo', $catinfo);
        $this->assign('list', $list);

        $this->V('anli_list');
    }

    public function show()
    {
        $userinfo = $this->userinfo;
        $nav_array = $this->difang_model->getCategoryArray($userinfo['uid'], 0);

        $id = intval($this->getParam('aid'));
        if (empty($id)) {
            $this->redirect('请选择图库！');
        }
        //取文章内的图片数组和文章详情字段
        $info = $this->hotel_model->getImageInfo($id);
        if (!$info) {
            $this->redirect('选择的酒店不存在!');
            exit();
        }
        $img = $this->hotel_model->getCfgBody('img', $info['imgurls']);
        $imgurl_array = $img[2];
        $imgtitle_array = $img[1];

        //增加一次点击数
        $this->show_model->saveArticleClick($id);

        //栏目信息
        $catinfo = $this->show_model->getCategoryInfoById($info['cat_id'], $this->userinfo['uid']);

        $this->assign('userinfo', $userinfo);
        $this->assign('nav_array', $nav_array);
        $this->assign('info', $info);
        $this->assign('catinfo', $catinfo);
        $this->assign('imgurl_array', $imgurl_array);
        $this->assign('imgtitle_array', $imgtitle_array);

        $this->V('anli_show');
    }

}